<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>分布式组件示例 :: Antora Docs</title>
    <meta name="generator" content="Antora 3.2.0-alpha.8">
    <link rel="stylesheet" href="../../../_/css/site.css">
  </head>
  <body class="article">
<header class="header">
  <nav class="navbar">
    <div class="navbar-brand">
      <a class="navbar-item" href="../../..">Antora Docs</a>
      <button class="navbar-burger" aria-controls="topbar-nav" aria-expanded="false" aria-label="Toggle main menu">
        <span></span>
        <span></span>
        <span></span>
      </button>
    </div>
    <div id="topbar-nav" class="navbar-menu">
      <div class="navbar-end">
        <a class="navbar-item" href="#">Home</a>
        <div class="navbar-item has-dropdown is-hoverable">
          <a class="navbar-link" href="#">Products</a>
          <div class="navbar-dropdown">
            <a class="navbar-item" href="#">Product A</a>
            <a class="navbar-item" href="#">Product B</a>
            <a class="navbar-item" href="#">Product C</a>
          </div>
        </div>
        <div class="navbar-item has-dropdown is-hoverable">
          <a class="navbar-link" href="#">Services</a>
          <div class="navbar-dropdown">
            <a class="navbar-item" href="#">Service A</a>
            <a class="navbar-item" href="#">Service B</a>
            <a class="navbar-item" href="#">Service C</a>
          </div>
        </div>
        <div class="navbar-item">
          <span class="control">
            <a class="button is-primary" href="#">Download</a>
          </span>
        </div>
      </div>
    </div>
  </nav>
</header>
<div class="body">
<div class="nav-container" data-component="component-b" data-version="3.1">
  <aside class="nav">
    <div class="panels">
<div class="nav-panel-menu is-active" data-panel="menu">
  <nav class="nav-menu">
    <button class="nav-menu-toggle" aria-label="Toggle expand/collapse all" style="display: none"></button>
    <h3 class="title"><a href="../index.html">Component B</a></h3>
<ul class="nav-list">
  <li class="nav-item" data-depth="0">
<ul class="nav-list">
  <li class="nav-item" data-depth="1">
    <button class="nav-item-toggle"></button>
    <a class="nav-link" href="../index.html">欢迎</a>
<ul class="nav-list">
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="../xrefs-demo.html">交叉引用的演示</a>
  </li>
</ul>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="0">
<ul class="nav-list">
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="overview.html">模块1概述</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="collector-demo.html">Collector演示</a>
  </li>
  <li class="nav-item is-current-page" data-depth="1">
    <a class="nav-link" href="distributed-demo.html">分布式组件示例</a>
  </li>
</ul>
  </li>
</ul>
  </nav>
</div>
<div class="nav-panel-explore" data-panel="explore">
  <div class="context">
    <span class="title">Component B</span>
    <span class="version">3.1</span>
  </div>
  <ul class="components">
    <li class="component">
      <div class="title"><a href="../../../component-a/1.6.0/source-code.html">Component A</a></div>
      <ul class="versions">
        <li class="version is-latest">
          <a href="../../../component-a/1.6.0/source-code.html">1.6.0</a>
        </li>
      </ul>
    </li>
    <li class="component is-current">
      <div class="title"><a href="../index.html">Component B</a></div>
      <ul class="versions">
        <li class="version is-current is-latest">
          <a href="../index.html">3.1</a>
        </li>
        <li class="version">
          <a href="../../2.5/index.html">2.5-beta.1</a>
        </li>
        <li class="version">
          <a href="../../2.0/index.html">2.0</a>
        </li>
        <li class="version">
          <a href="../../1.0/index.html">1.0</a>
        </li>
      </ul>
    </li>
  </ul>
</div>
    </div>
  </aside>
</div>
<main class="article">
<div class="toolbar" role="navigation">
<button class="nav-toggle"></button>
  <a href="../index.html" class="home-link"></a>
<nav class="breadcrumbs" aria-label="breadcrumbs">
  <ul>
    <li><a href="../index.html">Component B</a></li>
    <li><a href="distributed-demo.html">分布式组件示例</a></li>
  </ul>
</nav>
<div class="page-versions">
  <button class="version-menu-toggle" title="Show other versions of page">3.1</button>
  <div class="version-menu">
    <a class="version is-current" href="distributed-demo.html">3.1</a>
    <a class="version is-missing" href="../../2.5/index.html">2.5-beta.1</a>
    <a class="version is-missing" href="../../2.0/index.html">2.0</a>
    <a class="version is-missing" href="../../1.0/index.html">1.0</a>
  </div>
</div>
</div>
  <div class="content">
<aside class="toc sidebar" data-title="Contents" data-levels="2">
  <div class="toc-menu"></div>
</aside>
<article class="doc">
<h1 class="page">分布式组件示例</h1>
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>本页面用于演示分布式组件（Distributed Component Versions）。</p>
</div>
<div class="paragraph">
<p>目标是将另一仓库中的程序代码作为本仓库的examples。</p>
</div>
<div class="paragraph">
<p>首先创建另一个仓库<em>antora-demo-b-plus</em>，其文件结构如下。</p>
</div>
<div id="bm-dcv-1" class="literalblock">
<div class="title">antora-demo-b-plus的文件结构</div>
<div class="content">
<pre>docs/
  antora.yml
  modules/
    module-one/
      examples/
        hello_world.py</pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_创建分布式组件"><a class="anchor" href="#_创建分布式组件"></a>创建分布式组件</h2>
<div class="sectionbody">
<div class="paragraph">
<p>只要将两个组件的antora.yml文件指定为相同的组件名称和版本号，Antora就会将它们视为属于同一组件版本，即使这些源文件是从多个位置收集而来的。</p>
</div>
<div class="paragraph">
<p>因此，将<a href="#bm-dcv-1">antora-demo-b-plus的文件结构</a>中的<em>antora.yml</em>内容定义如下：</p>
</div>
<div class="listingblock">
<div class="content">
<pre>name: component-b
version: '3.1'</pre>
</div>
</div>
<div class="paragraph">
<p>再在playbook中添加内容源：</p>
</div>
<div class="listingblock">
<div class="content">
<pre>content:
  sources:
  - url: ../antora-quickstart/antora-demo-b-plus <i class="conum" data-value="1"></i><b>(1)</b>
    branches: HEAD
    start_path: docs</pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>远程仓库需替换为git url。</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>然后<em>antora-demo-b-plus</em>的<em>module-one/examples</em>文件夹就相当于合并到了<em>antora-demo-b</em>的<em>module-one/examples</em>。在此页面中使用如下代码：</p>
</div>
<div class="literalblock">
<div class="content">
<pre>include::example$hello_world.py[]</pre>
</div>
</div>
<div class="paragraph">
<p>效果如下：</p>
</div>
<div class="listingblock">
<div class="title">hello_world.py</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-python hljs" data-lang="python"># Python 的 Hello World 程序
print("Hello, World!")</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_在分布式组件中使用collector"><a class="anchor" href="#_在分布式组件中使用collector"></a>在分布式组件中使用Collector</h2>
<div class="sectionbody">
<div class="paragraph">
<p>在仓库<em>antora-demo-b-plus</em>中创建<em>src/cpp</em>目录，其中包含了<em>hello_world.cpp</em>。如下。</p>
</div>
<div id="bm-dcv-2" class="literalblock">
<div class="title">增加了src目录的文件结构</div>
<div class="content">
<pre>docs/
  antora.yml
  modules/
    module-one/
      examples/
        hello_world.py
src/
  cpp/
    hello_world.cpp
  rust/
    hello_world.rs</pre>
</div>
</div>
<div class="paragraph">
<p>在<em>antora.yml</em>中注册Collector扩展，如下：</p>
</div>
<div class="listingblock">
<div class="content">
<pre>name: component-b
version: '3.1'
ext:
  collector:
    scan:
      dir: src/cpp
      into: modules/module-one/examples</pre>
</div>
</div>
<div class="paragraph">
<p>也就是将<em>src/cpp</em>文件夹映射到<em>module-one/examples</em>。</p>
</div>
<div class="paragraph">
<p>然后在此页面中使用如下代码：</p>
</div>
<div class="literalblock">
<div class="content">
<pre>include::example$hello_world.cpp[]</pre>
</div>
</div>
<div class="paragraph">
<p>效果如下：</p>
</div>
<div class="listingblock">
<div class="title">hello_world.cpp</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-cpp hljs" data-lang="cpp">#include &lt;iostream&gt;

int main() {
    std::cout &lt;&lt; "Hello, World!" &lt;&lt; std::endl;
    return 0;
}</code></pre>
</div>
</div>
</div>
</div>
</article>
  </div>
</main>
</div>
<footer class="footer">
  <p>This page was built using the Antora default UI.</p>
  <p>The source code for this UI is licensed under the terms of the MPL-2.0 license.</p>
</footer>
<script id="site-script" src="../../../_/js/site.js" data-ui-root-path="../../../_"></script>
<script async src="../../../_/js/vendor/highlight.js"></script>
  </body>
</html>
